#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>

typedef struct BinaryTreeNode
{
	int val;
	struct BinaryTreeNode* left;
	struct BinaryTreeNode* right;
}TreeNode;

int MaxDepth(TreeNode* root)
{
	if (root == NULL)
	{
		return 0;
	}
	int lefthigh = MaxDepth(root->left);
	int righthigh = MaxDepth(root->right);
	return lefthigh > righthigh ? lefthigh + 1 : righthigh + 1;
}

TreeNode* BuyNode(int value)
{
	TreeNode* newnode = (TreeNode*)malloc(sizeof(TreeNode));
	if (newnode == NULL)
	{
		perror("newnode malloc:");
		return NULL;
	}
	newnode->val = value;
	newnode->left = NULL;
	newnode->right = NULL;
	return newnode;
}

TreeNode* CreateTree()
{
	TreeNode* node1 = BuyNode(3);
	TreeNode* node2 = BuyNode(9);
	TreeNode* node3 = BuyNode(20);
	TreeNode* node4 = BuyNode(15);
	TreeNode* node5 = BuyNode(7);
	node1->left = node2;
	node1->right = node3;
	node2->left = NULL;
	node2->right = NULL;
	node3->left = node4;
	node3->right = node5;
	return node1;
}

int main()
{
	TreeNode* Tree = CreateTree();
	printf("%d\n", MaxDepth(Tree));
	return 0;
}